package com.yh.threadTest.pojo;

/**
 * @ClassName MyRunnable
 * @Description TODO
 * @Author 0715-YuHao
 * @Date 2020/11/11 14:11
 */
public class MyRunnable implements Runnable{

    private int count = 10;

    private Object o = new Object();

    @Override
    public void run() {
        while (true) {
            synchronized (o) {
                if (count > 0) {
                    System.out.println(Thread.currentThread().getName() + ":正在卖票");
//                    try {
//                        Thread.sleep(1000);
//                    } catch (InterruptedException e) {
//                        e.printStackTrace();
//                    }
                    count--;
                    System.out.println("卖票成功，余票：" + count);
                }else {
                    break;
                }
            }
        }
    }
}
